﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using Maticsoft.DBUtility;

namespace ElingOA6_DSJCJ.DAL
{
    /// <summary>
    /// 专题专栏模版 数据类
    /// </summary>
    public class ClsTempl
    {
        /// <summary>
        /// 构造函数
        /// </summary>
        public ClsTempl()
        {
        }
        /// <summary>
        /// 获得数据列表
        /// <creator>wangl</creator>
        /// <date>2013-07-24</date>
        /// </summary>
        /// <param name="entityNo">公司编号</param>
        /// <returns>模版列表</returns>
        public DataSet GetListByEntityNo(string entityNo)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select FClsTemplID,FTemplName,FEntityNo,FTemplShowPath,FTemplTopPicPath ");
            strSql.Append(" FROM t_ClsTempl ");
            strSql.Append(" WHERE FEntityNo=@FEntityNo");
            SqlParameter[] parameters = {
					new SqlParameter("@FEntityNo", SqlDbType.NVarChar,12)
                                        };
            parameters[0].Value = entityNo;
            return DbHelperSQL.Query(strSql.ToString(), parameters);
        }
        /// <summary>
        /// 得到一个对象实体
        /// <creator>wangl</creator>
        /// <date>2013-08-02</date>
        /// </summary>
        public ElingOA6_DSJCJ.Model.ClsTempl GetModel(decimal clsTemplID, string entityNo)
        {

            StringBuilder strSql = new StringBuilder();
            strSql.Append("select  top 1 FClsTemplID,FTemplName,FEntityNo,FTemplShowPath,FTemplTopPicPath from t_ClsTempl ");
            strSql.Append(" where FClsTemplID=@FClsTemplID AND FEntityNo=@FEntityNo");
            SqlParameter[] parameters = {
					new SqlParameter("@FClsTemplID", SqlDbType.Decimal),
                    new SqlParameter("@FEntityNo", SqlDbType.NVarChar,12)
			};
            parameters[0].Value = clsTemplID;
            parameters[1].Value = entityNo;
            ElingOA6_DSJCJ.Model.ClsTempl model = new ElingOA6_DSJCJ.Model.ClsTempl();
            DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters);
            if (ds.Tables[0].Rows.Count > 0)
            {
                return DataRowToModel(ds.Tables[0].Rows[0]);
            }
            else
            {
                return null;
            }
        }

        /// <summary>
        /// 得到一个对象实体
        /// <creator>wangl</creator>
        /// <date>2013-07-24</date>
        /// </summary>
        public ElingOA6_DSJCJ.Model.ClsTempl DataRowToModel(DataRow row)
        {
            ElingOA6_DSJCJ.Model.ClsTempl model = new ElingOA6_DSJCJ.Model.ClsTempl();
            if (row != null)
            {
                if (row["FClsTemplID"] != null && row["FClsTemplID"].ToString() != "")
                {
                    model.FClsTemplID = decimal.Parse(row["FClsTemplID"].ToString());
                }
                if (row["FTemplName"] != null)
                {
                    model.FTemplName = row["FTemplName"].ToString();
                }
                if (row["FEntityNo"] != null)
                {
                    model.FEntityNo = row["FEntityNo"].ToString();
                }
                if (row["FTemplShowPath"] != null)
                {
                    model.FTemplShowPath = row["FTemplShowPath"].ToString();
                }
                if (row["FTemplTopPicPath"] != null)
                {
                    model.FTemplTopPicPath = row["FTemplTopPicPath"].ToString();
                }
            }
            return model;
        }
    }
}
